class Library:
  # 定义类属性
  total_books = 3000
  loaned_books = 2463

  def __init__(self, name):
    self.name = name
    print(f"{self.name}图书馆")

  @classmethod
  def getMsg(cls):
    '''
    获取当前书籍信息
    '''
    print(f"总书籍数{cls.total_books}本")
    print(f"已借出{cls.loaned_books}本")
    print(f"还可以借阅{cls.total_books - cls.loaned_books}本")

  @classmethod
  def addBooks(cls, nums):
    '''
    添加书籍
    :param nums: 添加的书籍总数
    :return: 书籍总数
    '''
    cls.total_books += nums
    return cls.total_books

  def repaidBooks(self, nums):
    '''
    还书
    :param nums: 还回的书籍总数
    :return:借出去的书总数
    '''
    if 0 < nums < Library.loaned_books:
      Library.loaned_books -= nums        # 实例方法，访问类属性需要用类名
      return Library.loaned_books
    else:
      print("还书数量超出借出范围，还书失败，请核实！")

  def borrowBooks(self, nums):
    '''
    借书
    :param nums: 借出的书籍总数
    :return: 借出的书籍总数
    '''
    if Library.total_books - Library.loaned_books > nums:
      Library.loaned_books += nums        # 实例方法，访问类属性需要用类名
      return Library.loaned_books
    else:
      print("书不够借")


l = Library("aa")
print("------------")
# 新进1000本
print("进书之后的状态")
Library.addBooks(1000)
Library.getMsg()
print("------------")
# 再借出去386本
print("借书之后的状态")
l.borrowBooks(386)
Library.getMsg()
print("------------")
# 还回来65本
print("还书之后的状态")
l.repaidBooks(65)
Library.getMsg()
